<template>
  <div>
    <div>
      <a-form class="form-sty" @submit="orgSubmit" :form="form">
        <a-row>
          <a-col style="margin-top:80px;margin-bottom:30px;" :sm="{ span:5 }" class="formGroupTitle">
            重置登录密码</a-col>
        </a-row>
        <a-form-item :label-col="{ span: 5 }" :wrapper-col="{ span: 8,offset:1 }" label="账号">
          <a-input v-decorator="[
                      'orgName',
                      {rules: [{ required: true, message: '请输入合作机构号', whitespace: true}]}
                ]" size="large" placeholder="请输入合作机构号">
            <a-icon slot="prefix" type="mail" />
          </a-input>
        </a-form-item>
        <a-row>
          <a-col style="margin-bottom:20px;color:#116cb7;" :sm="{ span:12,offset:6 }">
            通过“手机验证”找回</a-col>
        </a-row>
        <a-row>
          <a-col style="margin-bottom:20px;" :sm="{ span:12,offset:6 }">
            <a-button type="primary" htmlType="submit" class="but_sty">立即重置</a-button>
          </a-col>
        </a-row>
      </a-form>
      <!-- <div class="type">
        <span class="span-wid">通过“手机验证”找回</span>
        <a-button type="primary"  @click="gotype2">立即重置</a-button>
      </div>-->

      <!-- <a-layout-content>
        <router-view style="padding-top: 220px;"></router-view>
      </a-layout-content>-->
      <!-- <a-layout-footer>Footer</a-layout-footer> -->
      <!-- </a-layout> -->
    </div>
  </div>
</template>

<script>
  import AForm from "ant-design-vue/es/form/Form";
  import ATabs from "ant-design-vue/es/tabs";
  import GlobalFooter from "../../layouts/GlobalFooter";
  import AFormItem from "ant-design-vue/es/form/FormItem";
  import AInput from "ant-design-vue/es/input/Input";
  import AIcon from "ant-design-vue/es/icon";
  import AInputGroup from "ant-design-vue/es/input/Group";
  import AButton from "ant-design-vue/es/button/button";
  import ACol from "ant-design-vue/es/grid/Col";
  import ARow from "ant-design-vue/es/grid/Row";
  import ACheckbox from "ant-design-vue/es/checkbox/Checkbox";
  import AAlert from "ant-design-vue/es/alert/index";
  import pick from "lodash.pick";
  import api from "@/common/api";
  import { get, post } from "@/common/api";
  import moment from "moment";
  const ATabPane = ATabs.TabPane;

  export default {
    name: "Login",
    components: {
      AAlert,
      ACheckbox,
      ACol,
      ARow,
      AButton,
      AInputGroup,
      AIcon,
      AInput,
      AFormItem,
      GlobalFooter,
      ATabPane,
      ATabs,
      AForm
    },
    data() {
      return {
        form: this.$form.createForm(this),
        logging: false,
        error: "",
        per: false,
        login: false,
        orgName: '',
        formItemLayout: {
          labelCol: {
            xs: { span: 24 },
            sm: { span: 5 }
          },
          wrapperCol: {
            xs: { span: 24 },
            sm: { span: 12, offset: 1 },
            md: { span: 10, offset: 1 }
          }
        },
      };
    },
    computed: {},
    mounted() { },
    methods: {
      orgSubmit(e) {
        e.preventDefault();
        this.form.validateFields((err, values) => {
          if (!err) {
            this.orgName = values.orgName;
            // console.log("!err");
            this.ifFirst();
          }
        });
      },
      //判断是否第一次
      ifFirst(){
        this.$axios.get("/agent/safe/isFirstLogin/" + this.orgName).then(res => {
          if(res.data.data.isFirstLogin == false){
            this.userInfo();
          }else{
            this.$message.info("无法重置密码，请使用初始密码登录")
          }
        })
      },
      // 账户信息
      userInfo() {
        let data = {
          username: this.orgName
        };
        api.AccountInfo(data, res => {
          console.log("res", res);
          if (res.code == "OK") {
            let mobileNo = res.data.mobileNo;
            let securityQuestion = res.data.securityQuestion;
            let userName = res.data.userName;
            let memberNo = res.data.memberNo;
            localStorage.setItem('mobileNo', mobileNo);
            localStorage.setItem('securityQuestion', securityQuestion);
            localStorage.setItem('userName', userName);
            localStorage.setItem('memberNo', memberNo);
            this.$router.push("/org/passwordretrieve1");
          } else {
            console.log("res", res);
            this.$message.error(res.message);
          }
        });
      },
      handleChange(value) {
        console.log(value);
      },
      gotype1() {
        this.$router.push("/org/passwordretrieve1");
      },
      gotype2() {
        this.$router.push("/org/passwordretrieve2");
      },
      gologin() {
        this.$router.push("/home/loginall");
      },
    }
  };
</script>

<style lang="less" scoped>
  .form-sty {
    padding: 30px 20px;
    width: 70%;
    margin: 0 auto;
  }

  span {
    cursor: pointer;
  }

  .formGroupTitle {
    font-size: 20px;
    font-weight: 500;
    text-align: right;
    color: #333;
  }

  .but_sty {
    width: 30%;
  }
</style>